import jsonp from 'jsonp'
import {message} from 'antd';
import ajax from './ajax';

/*
包含应用中所有接口请求函数的模块
每个函数的返回值都是Promise

基本要求：能根据接口文档定义接口请求函数
 */

const BASE = ''

    /**
     * 官网
     */

export const reqStatistics = () => ajax(BASE + '/statistics/',{},)//



//登录
export const reqLogin = (username, password) => ajax(BASE + '/companylogin', {username, password}, 'POST')//和上面的写法效果一致


/*
对应后台的人事招聘后台模块
 */

/*
* 公司信息*/
export const reqCompanyInformation = () => ajax(BASE + '/employer/company',{})//查看公司基本信息
export const reqUpdateCompanyInformation = (updateComInformation,companyId) => ajax(BASE + '/employer/company/'+companyId+'/',updateComInformation,"PUT")//更改公司基本信息
/*
* 人事信息*/

/*
* 消息通知*/


/*
* 充值*/
export const reqCompanyRecharge = () => ajax(BASE + '/employer/company',{})//查看当前公司积分值
export const reqRecharge = (rechargeInformation) => ajax(BASE + '/operations/recharge/',rechargeInformation,'POST')//当前公司积分充值

/*
* 公司招聘*/

//1招聘信息
export const reqCompanyRecruit = (page,PAGE_SIZE) => ajax(BASE + '/employer/com_recruit',{page,PAGE_SIZE})
export const reqAddCompanyRecruit = (addRecruitInformation) => ajax(BASE + '/employer/com_recruit/',{addRecruitInformation},'POST')
export const reqUpdateCompanyRecruitState = (updateRecruitState,recruitId) => ajax(BASE + '/employer/com_recruit/'+recruitId+'/',updateRecruitState,'PUT')
export const reqCity = (type) => ajax(BASE + '/resources/city',{type})//城市的读取
export const reqSkill = () => ajax(BASE + '/resources/skill',{})//技能要求的读取
export const reqPosition = () => ajax(BASE + '/resources/position',{})//岗位的读取
export const reqTrade = () => ajax(BASE + '/resources/trade',{})//行业的读取

//2求职者信息
export const reqLookEmployee = (page,PAGE_SIZE) => ajax(BASE + '/employee/list/',{page,PAGE_SIZE})//求职者信息列表


//3招聘订单
export const reqLookRecruit = (page,PAGE_SIZE) => ajax(BASE + '/operations/com_order',{page,PAGE_SIZE})//订单列表
export const reqUpdateRecruitOrder = (status,orderId) => ajax(BASE + '/operations/com_order/'+orderId+'/',status,'PUT')//更改订单状态

/*
json请求的接口请求函数
 */
export const reqWeather = (city) => {
    return new Promise((resolve, reject) => {
        const url = `http://api.map.baidu.com/telematics/v3/weather?location=${city}&output=json&ak=3p49MVra6urFRGOT9s8UBWr2`
        //发送jsonp请求
        jsonp(url, {}, (err, data) => {
            //如果成功了
            if (!err && data.status === 'success') {
                //取出需要的数据
                const {dayPictureUrl, weather} = data.results[0].weather_data[0]
                resolve({dayPictureUrl, weather})
            } else {
                //如果失败了
                message.error('获取天气信息失败')
            }
        })

    })
}
